package models

import "time"
import "gorm.io/gorm"
import "go_part/utils"
//import "fmt"

type ApprovalStep struct{
	gorm.Model
	Name string
	StepID string
	StepNo string
	ApprovalModuleID string
	CompanyID string
	DeparkmentID string
	LevelLocalID string
	LoginTime time.Time
	IsLogout bool
	DeviceInfo string
 }

func (table *ApprovalStep) TableName() string {

	return "approval_step_basic"
}

func GetApprovalStepList() []*ApprovalStep { 
	data := make([]*ApprovalStep,10)
	utils.DB.Find(&data)
	// for _,v : = range data {
	// 	fmt.Println(v)
	// }
	return data
}

func FindApprovalStepByName(name string) ApprovalStep {
	user := ApprovalStep{}
	utils.DB.Where("name = ?",name).Find(&user)
	return user
}

func FindApprovalStepByID(id uint) ApprovalStep {
	user := ApprovalStep{}
	utils.DB.Where("id = ?",id).First(&user)
	return user
}

func FindApprovalStepByStepID(id string,CompanyID string) ApprovalStep {
	user := ApprovalStep{}
	utils.DB.Where("step_id = ? and company_id = ?",id,CompanyID).First(&user)
	return user
}

func FindApprovalStepByCompanyID(id string, ApprovalModuleID string) []*ApprovalStep {
	user := make([]*ApprovalStep,100)
	utils.DB.Where("company_id = ? and approval_module_id = ?",id,ApprovalModuleID).Find(&user)
	return user
}

func CreateApprovalStep(user ApprovalStep) *gorm.DB {
	
	return utils.DB.Create(&user)
}

func DeleteApprovalStep(user ApprovalStep) *gorm.DB {
	
	return utils.DB.Delete(&user)
}

func UpdateApprovalStep(user ApprovalStep) *gorm.DB {
	
	return utils.DB.Model(&user).Updates(ApprovalStep{Name: user.Name, DeparkmentID: user.DeparkmentID,LevelLocalID: user.LevelLocalID,DeviceInfo: user.DeviceInfo})
}